home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
PredatorPrey
/
calc_dipshit.c
< prev
next >
Wrap
Text File
|
1996-06-22
|
17KB
|
697 lines
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Prototype HP15C Calculator */
/* James C. Ullrey */
/* INRESCO */
/* © 1990 */
/* Version 13.97a */
/* */
/* DIP_SHIT SEGMENT */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/*****************************************************************/
/* I N C L U D E S */
/*****************************************************************/
#ifndef __C14__
#include "PredatorPrey.h"
#endif
#include "Globals.h"
#ifndef __RED__
#include "ResourceDefs.h"
#endif
#include "calc_dipshit.h"
#include <Sound.h>
#include "DialogAids.h"
#define DoneButton 1
#define Field3 3
#define Field4 4
#define Field5 5
/********************************************************************
/* G L O B A L V A R I A B L E D E C L A R A T I O N S
/********************************************************************/
extern Boolean stillWizard;
extern Boolean WizAttempt;
extern Boolean PassAttempt;
extern Boolean gIsWizard;
extern Boolean gLoadProgEnabled;
extern Str255 bufferOne;
extern Str255 bufferTwo;
extern Str255 bufferTwe;
extern long gTime;
const short kRevealedText = 4;
const short kGoAway = 18;
static const char kEnter = (char) 0x03;
static const char kReturn = (char) 0x0D;
static const char kSpace = ' ';
static const char kPeriod = '.';
static const char kBullet = '•';
TEHandle pMirrorEditText = nil;
TEHandle ppMirrorEditText = nil;
/*****************************************************************/
/* P R O T O T Y P E S
/*****************************************************************/
Boolean GetWiz ( WizRec *Wiz);
Boolean GetPass1 ( PassRec *Pass);
Boolean GetPass2 ( PassRec *Pass);
//extern void SetDText ( short itemNr,
// Str255 text
// );
void GetDText ( short itemNr,
Str255 text
);
extern void OutlineButton (short itemHit);
//extern pascal Boolean StandardFilter ( DialogPtr whichDialog,
// EventRecord *event,
// short *itemHit
// );
pascal Boolean PasswordProc1 ( DialogPtr theDialog,
EventRecord *theEvent,
short *itemHit);
pascal Boolean PasswordProc2 ( DialogPtr theDialog,
EventRecord *theEvent,
short *itemHit);
/* void DoThePreReg (void);*/
/* Boolean GetPreReg (PreRegRec *Reg);*/
/*****************************************************************/
/*****************************************************************/
/*
/* R O U T I N E S
/*
/*****************************************************************/
/*****************************************************************/
void dipshit_seg() {} /* for reference in "UnloadSeg()" calls */
/*****************************************************************/
/********************** DumbShit *********************************/
/*****************************************************************/
void DumbShit(short selector)
{
Str255 key2;
short i,j,k;
key2[0] = 28;
key2[1] = 't';
key2[2] = 'h';
key2[3] = 'e';
key2[4] = 'k';
key2[5] = 'e';
key2[6] = 'y';
key2[7] = 't';
key2[8] = 'o';
key2[9] = 'r';
key2[10] = 'e';
key2[11] = 'b';
key2[12] = 'e';
key2[13] = 'c';
key2[14] = 'c';
key2[15] = 'a';
key2[16] = 'c';
key2[17] = 'r';
key2[18] = 'y';
key2[19] = 'p';
key2[20] = 't';
key2[21] = 'o';
key2[22] = 'g';
key2[23] = 'r';
key2[24] = 'a';
key2[25] = 'p';
key2[26] = 'h';
key2[27] = 'i';
key2[28] = 'c';
switch(selector)
{
case 1:
j = map.SUPassword[0];
for(i = 1;i <= 28;i++)
{
map.mem4name[i] = (char)map.SUPassword[i%j] ^ (char)key2[i];
}
map.mem4name[0] = 28;
gIsWizard = TRUE;
stillWizard = TRUE;
for(i = 0;i <= 28;i++)
{
if(map.mem4name[i] == map.mem3name[i])
{
; /* do nothing */
}
else
{
gIsWizard = FALSE;
stillWizard = FALSE;
}
}
break;
case 2:
j = map.mem2name[0];
for(i = 1;i <= 28;i++)
{
map.mem4name[i] = (char)map.mem2name[i%j] ^ (char)key2[i];
}
for(i = 0;i <= 28;i++)
{
map.mem3name[i] = map.mem4name[i];
}
break;
}
}
/*****************************************************************/
/************************ DoWiz **********************************/
/*****************************************************************/
static void DoWiz(void)
{
WizRec WizInfo;
register WizRecPtr info;
short i,j;
/*short FanfareID;*/
Handle sound;
OSErr errCode;
info = &WizInfo;
info->Field3Text [0] = 0;
info->Field5Text [0] = 0;
if(GetWiz(&WizInfo))
{
/* use WizInfo */
if(info->Field3Text [0] != 0)
{
i = info->Field3Text [0];
for(j = 0;j<=i;j++)
{
map.SUName[j] = info->Field3Text[j];
/*map.mem2name[j] = info->Field3Text[j];*/
}
}
if(info->Field5Text [0] != 0)
{
WizAttempt = TRUE;
/*Delay(1,&startTick1);*/
i = info->Field5Text [0];
for(j = 0;j<=i;j++)
{
map.SUPassword[j] = info->Field5Text[j];
/*map.mem3name[j] = info->Field5Text[j];*/
}
}
DumbShit(1);
if(gIsWizard)
{
sound = GetResource ('snd ', FanfareID);
if (sound != NULL)
{
/* cw5 */ //errCode = SndPlay (NULL, sound, false);
}
DelMenuItem( GetMHandle(FILE_MENU_ID), 6 );
InsMenuItem( GetMHandle(FILE_MENU_ID), "\pOpen Program/L", 5 );
DelMenuItem( GetMHandle(FILE_MENU_ID), 7 );
InsMenuItem( GetMHandle(FILE_MENU_ID), "\pOpen Data", 6 );
if(!gLoadProgEnabled)
{
DisableItem(GetMHandle(FILE_MENU_ID), 6); /* LOAD_PROGRAM */
DisableItem(GetMHandle(FILE_MENU_ID), 7); /* IS NOW OPEN PROGRAM */
}
WizardMenu = GetMenu (WizardMenuID);
InsertMenu (WizardMenu, 0);
DrawMenuBar();
}
else
{
sound = GetResource ('snd ', BronxID);
if (sound != NULL)
{
/* cw5 */ //errCode = SndPlay (NULL, sound, false);
}
}
}
}
/*****************************************************************/
/********************** DoTheWiz *********************************/
/*****************************************************************/
void DoTheWiz(void)
{
DoWiz();
}
/*****************************************************************/
/*********************** GetWiz **********************************/
/*****************************************************************/
Boolean GetWiz(WizRec *Wiz)
{
GrafPtr wOldPort;
DialogPtr wizPtr;
Boolean result = TRUE;
Boolean done;
short itemHit;
register WizRecPtr info;
ModalFilterUPP gMyStandardFilterUPP;
if((wizPtr = GetNewDialog(WIZ_SCRN,NIL_PTR,(WindowPtr)MOVE_TO_FRONT) ) != NIL_PTR )
{
GetPort(&wOldPort );
/*CenterWindow( wizPtr );*/
ShowHide( wizPtr,TRUE ); /* Make window visible if invisible */
SetPort( wizPtr );
info = Wiz;
SetDText (Field3, info->Field3Text);
SetDText (Field5, info->Field5Text);
DrawDialog(wizPtr);
OutlineButton (1);
done = false;
gMyStandardFilterUPP = NewModalFilterProc(StandardFilter);
while (!done)
{
//ModalDialog((ProcPtr)StandardFilter,&itemHit);
ModalDialog(gMyStandardFilterUPP,&itemHit);
switch(itemHit)
{
case DoneButton:
done = true;
break;
case Field3:
GetDText (itemHit, info->Field3Text);
break;
case Field5:
GetDText (itemHit, info->Field5Text);
break;
}
}
/*gIsWizard = TRUE;*/
DisposDialog (wizPtr); /* Remove window from memory */
SetPort( wOldPort );
return (result);
}
}
/*****************************************************************/
/******************* PasswordProc1 *******************************/
/*****************************************************************/
pascal Boolean PasswordProc1( DialogPtr theDialog,
EventRecord *theEvent,
short *itemHit)
{
Boolean result;
char key; // key pressed by the user
Rect dummyRect; // Scratch rectangle for creating TERecord
TEHandle dialogTE;
Str255 password;
short iKind;
Handle iHandle;
Rect iRect;
result = FALSE;
if(pMirrorEditText == nil)
{
SetRect(&dummyRect, 0, 0, 0, 0);
pMirrorEditText = TENew(&dummyRect, &dummyRect);
}
if ((theEvent->what == keyDown) || (theEvent->what == autoKey))
{
key = theEvent->message & charCodeMask;
if (( key == kReturn) || (key == kEnter))
{
if (pMirrorEditText != nil)
{
TEDispose(pMirrorEditText);
pMirrorEditText = nil;
}
*itemHit = kGoAway;
result = TRUE;
}
else
{
if (key >= ' ')
{
theEvent->message &= ~charCodeMask;
theEvent->message |= '*';
}
dialogTE = ( (DialogPeek)theDialog)->textH;
(*pMirrorEditText)->selStart = (*dialogTE)->selStart;
(*pMirrorEditText)->selEnd = (*dialogTE)->selEnd;
TEKey(key, pMirrorEditText);
password[0] = (*pMirrorEditText)->teLength;
BlockMove(*((*pMirrorEditText)->hText),&password[1],password[0]);
GetDItem(theDialog, kRevealedText, &iKind,&iHandle, &iRect);
SetIText(iHandle,password);
}
}
return result;
}
/*****************************************************************/
/******************* PasswordProc2 *******************************/
/*****************************************************************/
pascal Boolean PasswordProc2( DialogPtr theDialog,
EventRecord *theEvent,
short *itemHit)
{
Boolean result;
char key; // key pressed by the user
Rect dummyRect; // Scratch rectangle for creating TERecord
TEHandle dialogTE;
Str255 password;
short iKind;
Handle iHandle;
Rect iRect;
result = FALSE;
if(ppMirrorEditText == nil)
{
SetRect(&dummyRect, 0, 0, 0, 0);
ppMirrorEditText = TENew(&dummyRect, &dummyRect);
}
if ((theEvent->what == keyDown) || (theEvent->what == autoKey))
{
key = theEvent->message & charCodeMask;
if (( key == kReturn) || (key == kEnter))
{
if (ppMirrorEditText != nil)
{
TEDispose(ppMirrorEditText);
ppMirrorEditText = nil;
}
*itemHit = kGoAway;
result = TRUE;
}
else /* PasswordProc2 */
{
if (key >= ' ')
{
theEvent->message &= ~charCodeMask;
theEvent->message |= '*';
}
dialogTE = ( (DialogPeek)theDialog)->textH;
(*ppMirrorEditText)->selStart = (*dialogTE)->selStart;
(*ppMirrorEditText)->selEnd = (*dialogTE)->selEnd;
TEKey(key, ppMirrorEditText);
password[0] = (*ppMirrorEditText)->teLength;
BlockMove(*((*ppMirrorEditText)->hText),&password[1],password[0]);
GetDItem(theDialog, kRevealedText, &iKind,&iHandle, &iRect);
SetIText(iHandle,password);
}
}
return result;
}
/*****************************************************************/
/********************** GetPass1 *********************************/
/*****************************************************************/
Boolean GetPass1(PassRec *Pass)
{
GrafPtr wOldPort;
DialogPtr passPtr;
Boolean result = TRUE;
Boolean done;
short itemHit;
register PassRecPtr info;
ModalFilterUPP gMyPasswordProcUPP;
if((passPtr = GetNewDialog(PASS_SCRN,NIL_PTR,(WindowPtr)MOVE_TO_FRONT) ) != NIL_PTR )
{
GetPort(&wOldPort );
/*CenterWindow( wizPtr );*/
ShowHide( passPtr,TRUE ); /* Make window visible if invisible */
SetPort( passPtr );
info = Pass;
SetDText (Field3, info->Field3Text);
SetDText (Field4, info->Field4Text);
/*SetDText (Field5, info->Field5Text);*/
DrawDialog(passPtr);
OutlineButton (1);
done = false;
gMyPasswordProcUPP = NewModalFilterProc(PasswordProc1);
while (!done)
{
//ModalDialog(PasswordProc1,&itemHit); /* Password screen 1 */
ModalDialog(gMyPasswordProcUPP,&itemHit); /* Password screen 1 */
switch(itemHit)
{
case DoneButton:
done = true;
break;
case Field3:
GetDText (itemHit, info->Field3Text);
GetDText ( 4, info->Field4Text);
break;
}
}
/*gIsWizard = TRUE;*/
DisposDialog (passPtr); /* Remove window from memory */
SetPort( wOldPort );
/*TEDispose( pMirrorEditText );*/
return (result);
}
}
/*****************************************************************/
/********************** GetPass2 *********************************/
/*****************************************************************/
Boolean GetPass2(PassRec *Pass)
{
GrafPtr wOldPort;
DialogPtr passPtr;
Boolean result = TRUE;
Boolean done;
short itemHit;
register PassRecPtr info;
ModalFilterUPP gMyPasswordProcUPP;
if((passPtr = GetNewDialog(PASS_SCRN2,NIL_PTR,(WindowPtr)MOVE_TO_FRONT) ) != NIL_PTR )
{
GetPort(&wOldPort );
/*CenterWindow( wizPtr );*/
ShowHide( passPtr,TRUE ); /* Make window visible if invisible */
SetPort( passPtr );
info = Pass;
SetDText (Field3, info->Field3Text);
SetDText (Field4, info->Field4Text);
SetDText (Field5, info->Field5Text);
DrawDialog(passPtr);
OutlineButton (1);
done = false;
gMyPasswordProcUPP = NewModalFilterProc(PasswordProc2);
while (!done)
{
//ModalDialog(PasswordProc2,&itemHit); /* Password screen 2 */
ModalDialog(gMyPasswordProcUPP,&itemHit); /* Password screen 2 */
switch(itemHit)
{
case DoneButton:
done = true;
break;
case Field3:
GetDText (itemHit, info->Field3Text);
GetDText ( 4, info->Field5Text);
break;
}
}
/*gIsWizard = TRUE;*/
DisposDialog (passPtr); /* Remove window from memory */
SetPort( wOldPort );
/*TEDispose( pMirrorEditText );*/
return (result);
}
}
/*****************************************************************/
/********************* DoPassword ********************************/
/*****************************************************************/
static void DoPassword(void)
{
PassRec PassInfo;
register PassRecPtr info;
short i,j;
Boolean match;
Handle sound;
OSErr errCode;
info = &PassInfo;
info->Field3Text [0] = 0;
info->Field4Text [0] = 0;
info->Field5Text [0] = 0;
if(GetPass1(&PassInfo))
{
/* use WizInfo */
if(info->Field4Text [0] != 0)
{
PassAttempt = TRUE;
i = info->Field4Text [0];
for(j = 0;j<=i;j++)
{
map.mem2name[j] = info->Field4Text[j];
}
}
}
info->Field3Text [0] = 0;
info->Field4Text [0] = 0;
if(GetPass2(&PassInfo))
{
/* use WizInfo */
if(info->Field5Text [0] != 0)
{
PassAttempt = TRUE;
i = info->Field5Text [0];
for(j = 0;j<=i;j++)
{
map.mem5name[j] = info->Field5Text[j];
}
}
}
if((j = map.mem2name[0]) == map.mem5name[0])
{
match = TRUE;
for(i = 1; i <= j;i++)
{
if(map.mem2name[i] == map.mem5name[i])
{
; /* do nothing */
}
else
{
match = FALSE;
}
}
if(match)
{
sound = GetResource ('snd ', FanfareID);
if (sound != NULL)
{
/* cw5 */ //errCode = SndPlay (NULL, sound, false);
}
DumbShit(2);
}
else
{
sound = GetResource ('snd ', BronxID);
if (sound != NULL)
{
/* cw5 */ //errCode = SndPlay (NULL, sound, false);
}
}
}
}
/*****************************************************************/
/******************** DoSetPassword ******************************/
/*****************************************************************/
void DoSetPassword(void)
{
DoPassword();
}
/*****************************************************************/
/******************** DoShareCopy ********************************/
/*****************************************************************/
void DoShareCopy ()
{
short i,j;
if(bufferOne [0] != 0)
{
i = bufferOne [0];
for(j = 0;j<=i;j++)
{
map.ownerName[j] = bufferOne[j];
}
}
if(bufferTwo [0] != 0)
{
i = bufferTwo [0];
for(j = 0;j<=i;j++)
{
map.ownerOrg[j] = bufferTwo[j];
}
}
if(bufferTwe [0] != 0)
{
i = bufferTwe [0];
for(j = 0;j<=i;j++)
{
map.ownerRegNo[j] = bufferTwe[j];
}
}
}
/*****************************************************************/
/*********************** DipShit *********************************/
/*****************************************************************/
void DipShit()
{
Str255 key;
short i,j,k;
long theNum;
j = map.ownerName[0];
if(j == 0) j = 1;
k = map.ownerOrg[0];
if(k == 0) k = 1;
key[0] = 28;
key[1] = 'a';
key[2] = 'n';
key[3] = 't';
key[4] = 'i';
key[5] = 'd';
key[6] = 'i';
key[7] = 's';
key[8] = 'e';
key[9] = 's';
key[10] = 't';
key[11] = 'a';
key[12] = 'b';
key[13] = 'l';
key[14] = 'i';
key[15] = 's';
key[16] = 'h';
key[17] = 'm';
key[18] = 'e';
key[19] = 'n';
key[20] = 't';
key[21] = 'a';
key[22] = 'r';
key[23] = 'i';
key[24] = 'a';
key[25] = 'n';
key[26] = 'i';
key[27] = 's';
key[28] = 'm';
Delay(1,&gTime);
for(i = 1;i <= 28;i++)
{
map.mem1name[i] = (char)map.ownerName[i%j] ^ (char)key[i];
}
for(i = 1;i <= 28;i++)
{
map.mem1name[i] ^= map.ownerOrg[i%k];
}
map.mem1name[0] = 28;
}